﻿using System;
using System.Collections;
using System.Collections.Generic;
using Gp.Scripts.Core;
using Gp.Scripts.Data.Skills;
using Gp.Scripts.Equip;
using Gp.Scripts.GUI;
using QFramework;

namespace Gp.Scripts.Data.Equip {
    public abstract class WeaponPhraseDecorator {
        public WeaponEntity Entity { get; private set; }
        public BaseUnit Unit => Entity.ComEquip.Unit;

        public void Init(WeaponEntity entity) {
            this.Entity = entity;
            OnInit();
        }


        protected virtual void OnInit() { }


        public virtual bool BeforeAttack() {
            return false;
        }

        public virtual bool AfterAttack(BaseUnit target, AttackActionResult atkResult) {
            return false;
        }

        public virtual bool BeforeBlock() {
            return false;
        }

        public virtual bool AfterBlock(AttackPreReaction args) {
            return false;
        }


        public virtual IEnumerator SmallTurnStart(TurnState state) {
            yield break;
        }

        public virtual void SmallTurnEnd(TurnState state) { }


        public virtual IEnumerable<BonusNumber> Bonus() {
            return Array.Empty<BonusNumber>();
        }

        public virtual IEnumerable<SkillTags> Tags() {
            return Array.Empty<SkillTags>();
        }


        public string Name => this.GetType().GetAttribute<WeaponPhraseAttribute>() is { } ab
            ? ab.Phrase
            : "";

        public virtual IEnumerable<WeaponAbilityEntity> WeaponAbility() {
            yield break;
        }




        public virtual ModifierValue DamageBonus() {
            return ModifierValue.Zero;
        }

        public virtual ModifierValue DamageBonus(BaseUnit target) {
            return DamageBonus();
        }
        
        
        





        #region  Utils Function
        protected WeaponAbilityEntity Build<T>() where T : WeaponAbilityEntityConfig {
            return WeaponAbilityEntity.Build<T>(Entity);
        }
        
        
        
        protected void TextEffect(string text) {
            TextEffect(Unit, text);
        }


        protected void TextEffect(BaseUnit unit, string text) {
            Global.Get<GridBattleGUISystem>().PlayFloatingText(unit, text);
        }
        #endregion

    }


    [AttributeUsage(AttributeTargets.Class, Inherited = false)]
    public class WeaponPhraseAttribute : Attribute {
        public string Phrase { get; }

        // public string Group { get; set; }

        public string Info { get; }


        public bool IsTypePhrase { get; } = false;

        public WeaponPhraseAttribute(string phrase) {
            Phrase = phrase;
            // Group = "";
        }

        public WeaponPhraseAttribute(string phrase, string info) {
            Phrase = phrase;
            Info = info;
        }

        public WeaponPhraseAttribute(string phrase, string info, bool isTypePhrase) {
            Phrase = phrase;
            Info = info;
            IsTypePhrase = isTypePhrase;
        }
    }
}